<?php
/**
 * Created by PhpStorm.
 * User: yys
 * Date: 2016/12/12
 * Time: 9:14
 */

namespace App\Services\PrintService;


use App\Services\ImgServices\ImgTool;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class PrintDataSaveService
{
     public function jobProcess(array $data){
         try{
            $img_path=$data['img_path'];
            $new_img_path=ImgTool::saveImgToDbByImgPath($img_path);
            Log::info('new_img_path:'.$new_img_path);
            $preview_image['product_print_image']=$new_img_path;
            $preview_image['product_print_thumbnail_image']='';
            $preview_image['product_preview_image_id']=$data['product_preview_image_id'];
            $res=$this->saveProductPreviewImages($preview_image);
         }catch (\Exception $e){
          Log::info($e);
          return false;
         }
     }
    /***
     * 打印图片插入数据
     * @param array $preview_image
     * @return bool
     */
     private function saveProductPreviewImages(array $preview_image){
         if(!isset($preview_image['product_preview_image_id'])){
             Log::info('saveProductPreviewImages product_preview_image_id传入错误');
             return false;
         }
         $preview_image['updated_at']=time();
         $num=DB::table('product_preview_images')
             ->where(array('product_preview_image_id'=>$preview_image['product_preview_image_id']))
             ->update($preview_image);
         return ($num===0)?false:true;
     }
}